﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Common.Utilities.DLR
{
    /// <summary>
    /// 
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class OrmFieldAttribute:Attribute
    {
        private readonly string mssqlFieldDataType;
        private string _ColumnName;
        /// <summary>
        /// 
        /// </summary>
        public string MssqlFieldDataType
        {
            get { return mssqlFieldDataType; }
        }

        /// <summary></summary>
        public string ColumnName
        {
            get
            {
                return this._ColumnName;
            }
            set
            {
                this._ColumnName = value;
            }
        }

        private SqlDbType _FieldDataType;
        /// <summary></summary>
        public SqlDbType FieldDataType
        {
            get
            {
                return this._FieldDataType;
            }
            set
            {
                this._FieldDataType = value;
            }
        }

        private int _Size;
        /// <summary></summary>
        public int Size
        {
            get
            {
                return this._Size;
            }
            set
            {
                this._Size = value;
            }
        }

        private OrmFieldSerializationMethod _SerializationMethod;
        /// <summary></summary>
        public OrmFieldSerializationMethod SerializationMethod
        {
            get
            {
                return this._SerializationMethod;
            }
            set
            {
                this._SerializationMethod = value;
            }
        }

        private bool _Mappable;
        /// <summary></summary>
        public bool Mappable
        {
            get
            {
                return this._Mappable;
            }
            set
            {
                this._Mappable = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="colName"></param>
        /// <param name="mssqlFieldDataType"></param>
        public OrmFieldAttribute(string colName, string mssqlFieldDataType)
        {
            this.mssqlFieldDataType = mssqlFieldDataType;
            this.ColumnName = colName;
            this.FieldDataType = SqlDbType.VarChar;
            this.Size = 50;
            this.SerializationMethod = OrmFieldSerializationMethod.DefaultSerialization;
            this.Mappable = true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="colName"></param>
        /// <param name="fieldDataType"></param>
        /// <param name="size"></param>
        /// <param name="fieldSerializationMethod"></param>
        public OrmFieldAttribute(string colName, SqlDbType fieldDataType, int size, OrmFieldSerializationMethod fieldSerializationMethod)
        {
            this.ColumnName = colName;
            this.FieldDataType = fieldDataType;
            this.Size = size;
            this.SerializationMethod = fieldSerializationMethod;
            this.Mappable = true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mappable"></param>
        public OrmFieldAttribute(bool mappable)
        {
            this.Mappable = mappable;
        }
    }
}
